package com.war.controller.system;

import com.war.pojo.system.User;
import com.war.pojo.system.Warehouse;
import com.war.service.safeManage.UserService;
import com.war.service.system.WarehouseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;

@Controller
@RequestMapping("/warehouse")
public class WarehouseController {
    @Autowired(required = false)
    WarehouseService warehouseService;

    @RequestMapping("/selectName")
    @ResponseBody
    public List<Warehouse> selectName(){
        return warehouseService.selectName();
    }

    //访问warehouseManage页面
    @RequestMapping("/warehouseList")
    public String list(Warehouse warehouse, ModelMap m){
        //查询分页数据
        HashMap<String, Object> map = warehouseService.select(warehouse);        //把数据传到前端
        m.put("info",map);
        //把查询条件传到前端
        m.put("CV",warehouse.getConValue());
        return "basicDataManage/warehouseManage/warehouseManage";
    }

    //打开添加页面
    @RequestMapping("/addWarePage")
    public String addWarePage(){
        return "basicDataManage/warehouseManage/addWare";
    }

    //打开修改页面
    @RequestMapping("/editIWarePage")
    public String editIWarePage(Warehouse warehouse, ModelMap m){
        Warehouse w = warehouseService.selectByid(warehouse);
        //把数据传到前端
        m.addAttribute("warehouse",w);
        return "basicDataManage/warehouseManage/editIWare";
    }

        //处理修改的ajax请求
        @RequestMapping("/editIWare")
        @ResponseBody
        public HashMap<String,Object> editIWare(Warehouse warehouse){
            HashMap<String,Object> map = new HashMap<String,Object>();
            String info = warehouseService.editIWare(warehouse);
            map.put("info",info);
            return map;
        }

    //处理删除的ajax请求
    @RequestMapping("/delWare")
    @ResponseBody
    public HashMap<String,Object> delWare(Warehouse warehouse){
        HashMap<String,Object> map = new HashMap<String,Object>();
        String info = warehouseService.delWare(warehouse);
        map.put("info",info);
        return map;
    }

    //处理添加用户的ajax请求
    @RequestMapping("/addWare")
    @ResponseBody
    public HashMap<String,Object> addUser(Warehouse warehouse){
        HashMap<String,Object> map = new HashMap<String,Object>();
        String info = warehouseService.addWare(warehouse);
        map.put("info",info);
        return map;
    }

}
